//
// Created by liushuai on 2020/10/26.
//

#include "mergeTwoLists.h"
ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) {
  ListNode *head = nullptr;
  if (l1 == nullptr && l2 == nullptr)
    return nullptr;
  else if (l1 == nullptr)
    return l2;
  else if (l2 == nullptr)
    return l1;
  else {
    if (l1->val <= l2->val) {
      head = l1;
      head->next = mergeTwoLists(l1->next, l2);
    } else {
      head = l2;
      head->next = mergeTwoLists(l1, l2->next);
    }
    return head;
  }
}
